From 47ef534c21c3ee75404a76523d21176a179f71bb Mon Sep 17 00:00:00 2001 From: tsteven4 Date: Thu, 22 Aug 2013 01:19:47 +0000 Subject: [PATCH] fix a bug in the gpx reader that could cause the character data from the wrong element to become associated with the link/text element. --- gpsbabel/gpx.cc | 26 ++++++++-------- gpsbabel/reference/multiple-links-2.gpx | 34 +++++++++++++++++++++ gpsbabel/reference/multiple-links-2~gpx.gpx | 31 +++++++++++++++++++ gpsbabel/testo.d/multiurlgpx.test | 3 ++ 4 files changed, 81 insertions(+), 13 deletions(-) create mode 100644 gpsbabel/reference/multiple-links-2.gpx create mode 100644 gpsbabel/reference/multiple-links-2~gpx.gpx diff --git a/gpsbabel/gpx.cc b/gpsbabel/gpx.cc index 05e0bb9dd..e7b2a998b 100644 --- a/gpsbabel/gpx.cc +++ b/gpsbabel/gpx.cc @@ -58,7 +58,7 @@ static gpsbabel::File* oqfile; static gpsbabel::XmlStreamWriter* writer; static short_handle mkshort_handle; static const char* link_url; -static char* link_text; +static char* link_text = NULL; static const char* input_string = NULL; static int input_string_len = 0; @@ -690,9 +690,6 @@ gpx_start(void* data, const XML_Char* xml_el, const XML_Char** xml_attr) link_url = attr[1]; } break; - case tt_wpt_link_text: - link_text = cdatastr.mem; - break; case tt_rte: rte_head = route_head_alloc(); route_add_head(rte_head); @@ -1203,16 +1200,19 @@ gpx_end(void* data, const XML_Char* xml_el) case tt_wpt_link: //TODO: implement GPX 1.1 case tt_trk_trkseg_trkpt_link: //TODO: implement GPX 1.1 case tt_rte_rtept_link: - { - char* lt = link_text; - if (lt) { - lt = xstrdup(lrtrim(link_text)); + waypt_add_url(wpt_tmp, link_url, link_text); + if (link_text) { + xfree(link_text); + link_text = NULL; } - - waypt_add_url(wpt_tmp, link_url, lt); - link_text = NULL; - } - break; + break; + case tt_wpt_link_text: + if (cdatastrp[0]) { + link_text = xstrdup(lrtrim(cdatastrp)); + } else { + link_text = NULL; + } + break; case tt_unknown: end_something_else(); current_tag.truncate(pos); diff --git a/gpsbabel/reference/multiple-links-2.gpx b/gpsbabel/reference/multiple-links-2.gpx new file mode 100644 index 000000000..4162e1233 --- /dev/null +++ b/gpsbabel/reference/multiple-links-2.gpx @@ -0,0 +1,34 @@ + + + + + + + + + 001 + 3348 Martha St + 3348 Martha St + + + one + not me + + + two dots + + + + three dots + + + + + Waypoint + + + SymbolAndDescription + + + + diff --git a/gpsbabel/reference/multiple-links-2~gpx.gpx b/gpsbabel/reference/multiple-links-2~gpx.gpx new file mode 100644 index 000000000..f5b2bab4c --- /dev/null +++ b/gpsbabel/reference/multiple-links-2~gpx.gpx @@ -0,0 +1,31 @@ + + + + + + + + + 001 + 3348 Martha St + 3348 Martha St + + + one + + + two dots + + + + three dots + + + Waypoint + + + SymbolAndDescription + + + + diff --git a/gpsbabel/testo.d/multiurlgpx.test b/gpsbabel/testo.d/multiurlgpx.test index 586aa4263..32bcbdef8 100644 --- a/gpsbabel/testo.d/multiurlgpx.test +++ b/gpsbabel/testo.d/multiurlgpx.test @@ -5,3 +5,6 @@ rm -f ${TMPDIR}/mlink* gpsbabel -i gpx -f ${REFERENCE}/multiple-links.gpx -o gpx,gpxver=1.1 -F ${TMPDIR}/mlink-1.gpx compare ${REFERENCE}/multiple-links.gpx ${TMPDIR}/mlink-1.gpx +# test some more complicated gpx 1.1 linkTypes and a link with an empty text element +gpsbabel -i gpx -f ${REFERENCE}/multiple-links-2.gpx -o gpx,gpxver=1.1 -F ${TMPDIR}/mlink-2.gpx +compare ${REFERENCE}/multiple-links-2~gpx.gpx ${TMPDIR}/mlink-2.gpx -- 2.30.2